package com.example.logintest;

import android.app.Application;
import android.content.res.Configuration;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.room.Room;

import com.example.logintest.database.BookDataBase;

public class MainApplication extends Application {

    private static final String TAG = "MainApplication";

    private static MainApplication mApp;
    private BookDataBase bookDataBase;

    @Override
    public void onCreate() {
        super.onCreate();
        Log.d(TAG, "onCreate: ");
        mApp = this;
        bookDataBase = Room.databaseBuilder(
                mApp, BookDataBase.class, "BookInfo"
        ).addMigrations().allowMainThreadQueries().build();
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
        Log.d(TAG, "onTerminate: ");
    }

    public static MainApplication getInstance(){
        return mApp;
    }

    @Override
    public void onConfigurationChanged(@NonNull Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        Log.d(TAG, "onConfigurationChanged: ");
    }

    public BookDataBase getBookDB() {
        return bookDataBase;
    }
}
